package com.emergency.embackend.controller;

import com.emergency.embackend.common.R;
import com.emergency.embackend.entity.WikiType;
import com.emergency.embackend.service.WikiArticleService;
import com.emergency.embackend.service.WikiTypeService;
import com.emergency.embackend.service.WikiVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chddd
 * @description
 * @create 2024/2/22 21:49:43
 */
@RestController
@Slf4j
@RequestMapping("wiki/type")
public class WikiTypeController {
    @Autowired
    private WikiTypeService wikiTypeService;
    @Autowired
    private WikiArticleService wikiArticleService;
    @Autowired
    private WikiVideoService wikiVideoService;


    @GetMapping("/getWikiType")
    public R getWikiType(){
        return R.ok().put("data",wikiTypeService.getWikiType());
    }

    @GetMapping("delete")
    public R delete(@RequestParam("typeId") Long typeId){
        if(typeId==null){
            return R.error("参数不许为空");
        }
        //删除类型
        wikiTypeService.delete(typeId);
        //删除类型对应的视频和文章
        wikiArticleService.deleteByTypeId(typeId);
        wikiVideoService.deleteByTypeId(typeId);
        return R.ok();
    }
    @PostMapping("add")
    public R add(@RequestBody WikiType wikiType){
        if(wikiType==null){
            return R.error("参数为空");
        }
        wikiTypeService.add(wikiType);
        return R.ok();
    }
}
